package rsj.api.org.importdata;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import common.util.Assert;
import common.util.BoxUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.context.ApplicationContextUtil;
import rsj.job.statistic.IStatisticUsageJob;
import rsj.job.statistic.StatisticTestUsage;
import rsj.service.usage.IUsageTemplateMethod;

import java.sql.SQLException;
import java.time.LocalDate;

/**
 * 开始统计
 *
 * @author yuanqinglong
 * @since 2021/3/11 15:06
 */
@RestController
public class StartStatisticsController extends BaseLink {


    /**
     * 开始统计
     *
     * @param box 参数
     * @return 结果
     * @throws SQLException 异常
     */
    @Override
    @RequestMapping(value = "rsj_start_statistic")
    public Box executeLink(Box box) throws SQLException {
        MapNode data = box.getMapNode("data");
        String orgId = data.getValue("org_id");
        Assert.isNotBlank(orgId, "机构id不可为空");
        IStatisticUsageJob statisticUsageJob = ApplicationContextUtil.getApplicationContext().getBean(StatisticTestUsage.class);
        statisticUsageJob.performStatistics(LocalDate.now(), orgId, IUsageTemplateMethod.TEST_ENVIRONMENT);
        return BoxUtil.successBox(box);
    }
}
